class command {
	constructor(redocmd, undocmd){
		this.redo=redocmd;
		this.undo=undocmd;
	}
}

class UndoRedo {
	constructor(){
		this.undoSize=-1;
		this.redoStack=[];
		this.undoStack=[];
	}
	add(redocmd, undocmd){
		let cmd=new command(redocmd,undocmd);
		cmd.redo();
		this.undoStack.push(cmd);
		if (this.undoSize != -1 && this.undoStack.length > this.undoSize) {
			this.undoStack.shift();
		}
		this.redoStack=[];
	}
	undo(){
		if(this.undoStack.length == 0)
			return false;
		let cmd = this.undoStack.pop();
		this.redoStack.push(cmd);
		cmd.undo();
		return true;
	}
	redo(){
		if(this.redoStack.length == 0)
			return false;
		let cmd = this.redoStack.pop();
		this.undoStack.push(cmd);
		cmd.redo();
		return true;
	}
}
export default UndoRedo;